/* 置顶窗口画图类
  
  By setycyas @2025-02-24
*/

#Include "OrderMap.2.ahk"

class DrawWindow {

  ;构造函数,单个窗口制作时的size
  __New(xSize:=1366, ySize:=788){
    this._xSize := xSize
    this._ySize := ySize
    this._windows := OrderMap() ;窗口句柄map,[窗口名字] := 句柄
  }

  ;画一个窗口,返回句柄
  drawNew(wName, x, y, w, h, backColor:=0xFFFFFF){
    local _gui,params
    _gui := Gui("+AlwaysOnTop")
    params := "x0 y0 " . "w" . this._xSize . " h" . this._ySize
    _gui.BackColor := backColor
    _gui.show(params)
    params := x . "-" y . " W" . w . " H" . h
    WinSetRegion(params, _gui)
    this._windows[wName] := _gui
    return _gui
  }
  
  ;全体显示
  showAll(){
    local wName, _gui
    for wName, _gui in this._windows {
      _gui.show()
    }
  }
  ;全体隐藏
  hideAll(){
    local wName, _gui
    for wName, _gui in this._windows {
      _gui.hide()
    }
  }
  
  ;修改一个window的位置
  changeWindow(wName, x, y, w, h){
    local _gui := this._windows[wName]
    params := x . "-" y . " W" . w . " H" . h
    WinSetRegion(params, _gui)
  }
  ;修改透明度,0-255(完全不透明)
  changeTransparent(wName, n){
    local _gui := this._windows[wName]
    WinSetTransparent(n, _gui)
  }
}

/* 测试 
dw := DrawWindow()
dw.drawNew("1", 0, 0, 100, 100, 0xFF0000)
j:: {
  dw.changeWindow("1", 200, 200, 10, 50)
}
i:: {
  dw.changeTransparent("1", 20)
}
*/